#ifndef PACKAGE_H_
#define PACKAGE_H_

#define PACKAGE_DATA_COMMAND_TASK_LEN  (256)
#define PACKAGE_DATA_COMMAND_LEN       (PACKAGE_DATA_COMMAND_TASK_LEN + sizeof(unsigned int))
#define PACKAGE_DATA_LEN               (PACKAGE_DATA_COMMAND_LEN + 2 * sizeof(unsigned int))
#define PACKAGE_LEN                    (PACKAGE_DATA_LEN + 2 * sizeof(unsigned int))

#define PT_NONE           (0)
#define PT_HANDSHAKE      (1)
#define PT_HANDSHAKE_ACK  (2)
#define PT_RUN            (3)
#define PT_RUN_ACK        (4)
#define PT_FINISH         (7)

typedef struct _HandShakeAck{
	unsigned int type;
	unsigned int length;
	unsigned int serverid;
	unsigned int cpus;
}HANDSHAKE_ACK_PACKAGE, *PHANDSHAKE_ACK_PACKAGE;

typedef struct _Run{
	int id;
	char* task;
}RUN_PACKAGE, *PRUN_PACKAGE;

typedef struct _RunAck{
	unsigned int type;
	unsigned int length;
	int id;
}RUN_ACK_PACKAGE, *PRUN_ACK_PACKAGE;

typedef struct _Finish{
	unsigned int type;
	unsigned int length;
	int id;
}FINISH_PACKAGE, *PFINISH_PACKAGE;

typedef struct _DataPackage{
	unsigned int type;
	unsigned int length;
	unsigned char command[PACKAGE_DATA_COMMAND_LEN];
}DATA_PACKAGE, *PDATA_PACKAGE;

typedef struct _Package{
	unsigned char header;
	unsigned char data[PACKAGE_DATA_LEN];
	unsigned char tail;
}PACKAGE, *PPACKAGE;

extern int  pkg_get(PDATA_PACKAGE, unsigned char*, int);
extern void pkg_create_handshakeack_package(PPACKAGE, int, int);
extern void pkg_create_finish_package(PPACKAGE, int);
extern void pkg_create_runack_package(PPACKAGE, int);

#endif /* PACKAGE_H_ */
